#!/bin/bash

set -e

sleep 2 #等待设备启动

usb="RUNNING"
DHCP_usb0="dhclient usb0"
DHCP_usb1="dhclient usb1"

out_usb0=$(ifconfig | grep 'usb0'| cut -d, -f 3)
#echo $out_usb0
out_usb1=$(ifconfig | grep 'usb1'| cut -d, -f 3)
#echo $out_usb1

if [ "$out_usb0" == "$usb" ];then
        date >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        echo "usbJudge.sh -> result: usb0" >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        #echo "usb0"
        eval $DHCP_usb0 >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        #dhclient usb1 #ECM是外置拨号方式，模块IP需要传给主控 -> 启动DHCP
elif [ "$out_usb1" == "$usb" ];then
        date >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        echo "usbJudge.sh -> result: usb1" >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        #echo "usb1"
        eval $DHCP_usb1 >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        #dhclient usb1 #ECM是外置拨号方式，模块IP需要传给主控 -> 启动DHCP
else
        date >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        echo "usbJudge.sh -> usb0 or usb1 not RUNNING" >> /home/nvidia/HYSD_shell/systemShell.log 2>&1
        #echo "no usb0 or usb1"
fi

